package model;

import java.util.Random;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class DayMuiTen {
	private Image imgarrow;
	private Image imgarrowp;
	private Image imgbgrarr;
	private int numArrow=1;
	private int posArrow;
	public static int arrHuong[];
	private int arrArrow[];
	private boolean isPress[];
	private final int maxArrow=9;
	int xarrow=5,yarrow=20;
	int topleft=Graphics.TOP|Graphics.LEFT;
	public DayMuiTen()
	{
		try {
		imgarrow=Image.createImage("/arrowblue.png");
		imgarrowp=Image.createImage("/arrp.png");
		imgbgrarr = Image.createImage("/img.png");
		}
		catch (Exception e)
		{
			System.out.println("Loi load anh day mui ten");
		}
		//tao 4 huong
		arrHuong=new int[5];
		arrHuong[0]=Sprite.TRANS_NONE;
		arrHuong[1]=Sprite.TRANS_ROT90;
		arrHuong[2]=Sprite.TRANS_ROT180;
		arrHuong[3]=Sprite.TRANS_ROT270;
		arrHuong[4]=-1;
		
	}
	public int getNumArrow() {
		return numArrow;
	}
	public void setNumArrow(int numArrow) {
		this.numArrow = numArrow;
	}
	public int getPosArrow() {
		return posArrow;
	}
	public void setPosArrow(int posArrow) {
		this.posArrow = posArrow;
	}
	public boolean getIsPress(int i) {
		return isPress[i];
	}
	public void setIsPress(int i) {
		this.isPress[i]=true;
	}

	public int getHuong(int i)
	{
		if (i<numArrow) 
		return arrArrow[i];
		else return -2;
	}
	public void draw(Graphics g)
	{
		g.drawImage(imgbgrarr,0,15,topleft);
		for (int i=0;i<numArrow;i++){
		g.drawRegion(imgarrow, 0, 0, imgarrow.getWidth(),imgarrow.getHeight(),arrArrow[i], xarrow+i*25, yarrow,topleft);
		if (isPress[i])
			g.drawRegion(imgarrowp, 0, 0, imgarrowp.getWidth(),imgarrowp.getHeight(),arrArrow[i], xarrow+i*25, yarrow,topleft);
		}
	}
	public void pressFalse()
	{
		for(int i=0;i<numArrow;i++)
			isPress[i]=false;
	}
	
	public void randomArrow(int num)
	{
		numArrow=num;
		Random ran=new Random();
		arrArrow=new int[numArrow];
		isPress=new boolean[numArrow];
		for (int i=0;i<numArrow;i++)
		{
		
			arrArrow[i]=arrHuong[ran.nextInt(4)];
			isPress[i]=false;
		
		}
		
	}
	
	
}
